<?php

/**
 * Description of DatesController
 *
 * @author Francis
 */
class DatesController extends AppController {
    //put your code here
    
    public $uses = array('OrganisationAnniversary');
    
    public function beforeFilter() {
        parent::beforeFilter();
        
        $this->autoRender = false;
    }
    
    public function index() {
        
        $data = $this->request->data;
        
        $result = $this->OrganisationAnniversary->find('all', array(
            'conditions' => array(
                'OrganisationAnniversary.organisation_id' => $data['organisation_id'],
                'OrganisationAnniversary.active' => 1
            )
        ));
        
        return $this->_response($result);
    }
    
    public function update() {
        $data = $this->request->data;
        
        $result = $this->OrganisationAnniversary->save(array(
            'id' => isset($data['date_id']) ? $data['date_id'] : null,
            'organisation_id' => $data['organisation_id'],
            'name' => $data['date_name'],
            'active' => 1
        ));
        
        return $this->_response($result);
    }
    
    public function remove() {
        $data = $this->request->data;
        
        $result = $this->OrganisationAnniversary->save(array(
            'id' => $data['date_id'],
            'organisation_id' => $data['organisation_id'],
            'active' => 0
        ));
        
        return $this->_response($result);
    }
}
